package com.xique.door.controller;


import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.door.bean.domain.Visitor;
import com.xique.door.bean.request.commandV1.DeviceCommandDownloadRequest;
import com.xique.door.bean.request.commandV1.DeviceCommandUserInfoDownloadRequest;
import com.xique.door.biz.service.IDeviceCommandNewService;
import com.xique.door.biz.service.IDeviceCommandService;
import com.xique.door.constant.UserConstant;
import com.xique.door.service.IPermissionGroupUserService;
import com.xique.door.service.IVisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 权限组Controller
 *
 * @author ww
 * @date 2021-06-11
 */
@Deprecated
@Controller
@RequestMapping("/oms/accessDeviceCommand")
public class AccessDeviceCommandController extends BaseController
{
    private String prefix = "oms/accessDeviceCommand";

    @Autowired
    private IDeviceCommandService deviceCommandService;

    @Autowired
    private IVisitorService visitorService;

    @Autowired
    private IPermissionGroupUserService permissionGroupUserService;

    @Autowired
    private IDeviceCommandNewService deviceCommandNewService;

    /**
     * 同步单用户至设备
     * @return
     */
    @Log(title = "同步单用户至设备", businessType = BusinessType.COMMAND)
    @PostMapping("/downSingleUser")
    @ResponseBody
    public AjaxResult downSingleUser(DeviceCommandDownloadRequest request){
        //1、groupId  为空，  代表在用户列表下发，单用户可能存在多组
        //2、groupId 不为空， 代表在一个的权限组下发用户，单用户单组
        return deviceCommandService.downloadUserInfo(request);
    }

    /**
     * 同步所有用户至设备
param request
     * @return
     */
    @Log(title = "同步所有用户至设备", businessType = BusinessType.COMMAND)
    @PostMapping("/downAllUsers")
    @ResponseBody
    public AjaxResult downAllUsers(DeviceCommandDownloadRequest request){
        return deviceCommandService.downloadAllUserInfo(request);
    }

    /**
     * 同步所有用户至设备
     * @param request
     * @return
     */
    @Log(title = "同步所有卡片信息至设备", businessType = BusinessType.COMMAND)
    @PostMapping("/downAllCards")
    @ResponseBody
    public AjaxResult downAllCards(DeviceCommandDownloadRequest request){
        return deviceCommandService.downloadAllCardInfo(request);
    }

    /**
     * 同步访客信息至设备
     * @return
     */
    @Log(title = "同步访客信息至设备", businessType = BusinessType.COMMAND)
    @PostMapping("/downSingleVisitor")
    @ResponseBody
    public AjaxResult downSingleVisitor(DeviceCommandDownloadRequest request){
        Visitor visitor = visitorService.selectVisitorById(request.getVisitorId());
        request.setUserId(visitor.getUserId());
        request.setVisitor(visitor);
        DeviceCommandDownloadRequest deviceCommandDownloadRequest = new DeviceCommandDownloadRequest();
        deviceCommandDownloadRequest.setUserId(visitor.getUserId());
        deviceCommandDownloadRequest.setVisitor(visitor);
        deviceCommandDownloadRequest.setParkId(visitor.getParkId());
        DeviceCommandUserInfoDownloadRequest visitorRequest = new DeviceCommandUserInfoDownloadRequest();
        visitorRequest.setUserId(visitor.getId());
        visitorRequest.setFromType("admin");
        visitorRequest.setAsync(false);
        visitorRequest.setUserType(UserConstant.Type.VISITOR);
        return  deviceCommandNewService.userInfoDownload(visitorRequest);
    }
}
